package com.example.hehecat.yuejian1.mvp.presenter;

import android.util.Log;

import com.example.hehecat.yuejian1.mvp.contract.MyPictureContract;
import com.example.hehecat.yuejian1.mvp.model.MyPictureModel;
import com.example.hehecat.yuejian1.mvp.model.bean.PictureBean;
import com.example.hehecat.yuejian1.mvp.model.bean.SuccessBean;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Subscriber;
import static com.chad.library.adapter.base.listener.SimpleClickListener.TAG;

public class MyPicturePresenter implements MyPictureContract.Presenter {
    private MyPictureContract.View view;
    private MyPictureContract.Model model;

    public MyPicturePresenter(MyPictureContract.View view){
        this.view = view;
        model = new MyPictureModel();
    }

    @Override
    public void updateAdapterData(int user_id) {
        model.MyPicture(user_id, new Subscriber<List<PictureBean>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(List<PictureBean> pictureBeans) {
                Log.d(TAG,"onNext: " +pictureBeans.get(0).getPicturename());
                view.updateAdapterData(pictureBeans);
            }
        });
    }

    @Override
    public void deleteMyPicture(int user_id,int picture_id) {
        model.DeleteMyPicture(user_id, picture_id, new Callback<SuccessBean>() {
            @Override
            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                Log.d(TAG, "onResponse: delete pic"+response.body().getSuccess());
                Log.d(TAG, "onResponse: "+user_id + "    "+picture_id);
            }

            @Override
            public void onFailure(Call<SuccessBean> call, Throwable t) {

            }
        });
    }
}
